#include <bits/stdc++.h>
using namespace std;
#define pc(x) __builtin_popcount(x)

int main(){
    int n;
    scanf("%d", &n);
    while(n--){
        int a, b, c, d;
        scanf("%d.%d.%d.%d", &a, &b, &c, &d);
        int ans = pc(a) + pc(b) + pc(c) + pc(d);
        printf("%d\n", ans);
    }
}